<?php

/**
 * Base class for the view functionality.
 * Should not be called directly, rather it should always be extended from
 *
 * @access Ben Rowe
 */
class ViewBase
{
	/**
	 * The name of the action requested, used to calculate template names + stuff
	 *
	 * @access private
	 * @var string
	 */
	var $_name;
	
	/**
	 * The external has array from the controller
	 *
	 * @access private
	 * @var array
	 */
	var $_hash_ext = array();
	
	/**
	 * Constructor
	 * init the ext hash
	 * get the requested action name
	 * ensure that the custom view layer has a valid _render() method
	 * execute the view layer
	 *
	 * @access public
	 * @param array $controller_hash
	 * @return View
	 */
	function ViewBase($controller_hash)
	{
		$this->_hash_ext = $controller_hash;
		$this->_getName();
		$this->_validateClass();
		$this->_exec();
	}
	
	/**
	 * Get the name of the section, and view name being requested
	 *
	 * @access private
	 * @return boolean
	 */
	function _getName()
	{
		$name = get_class($this);
		$this->_name = substr($name, 0, strrpos($name, '_'));
		return true;
	}
	
	/**
	 * verify that this class has been extended by a valid view class by 
	 * checking the extiance of the _render() method
	 *
	 * @access private
	 * @return null
	 */
	function _validateClass()
	{
		
		if(!method_exists($this, '_render')) {
			die('The requested view ('.$this->_name.') is not valid: does not contain a _render() method!');
		}
	}
}

?>